package com.controller;

import com.request.ProjectCreateRequest;
import com.request.ProjectDeleteRequest;
import com.service.ProjectService;
import com.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author rkc
 * @date 2022/8/25 15:39
 */
@RestController
@RequestMapping("/api/v1/pro")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    /**
     * 得到websocket
     * @return
     */
    @GetMapping("get_websocket/{pid}")
    public JsonData getWebsocket(@PathVariable("pid") Integer pid) {
        return projectService.getWebsocketUrlByProjectId(pid);
    }

    /**
     * 查询所有构建工具
     * @return
     */
    @GetMapping("select_build_tools")
    public JsonData selectBuildTools() {
        return projectService.selectBuildTools();
    }

    /**
     * 删除项目
     * @param projectDeleteRequest
     * @return
     */
    @PostMapping("delete")
    public JsonData delete(@RequestBody ProjectDeleteRequest projectDeleteRequest) {
        return projectService.deletePro(projectDeleteRequest);
    }

    /**
     * 创建项目
     * @param projectCreateRequest
     * @return
     */
    @PostMapping("create")
    public JsonData create(@RequestBody ProjectCreateRequest projectCreateRequest) {
        return projectService.createPro(projectCreateRequest);
    }

    /**
     * 查询自己所有项目列表
     * @return
     */
    @GetMapping("select_all")
    public JsonData selectAll() {
        return projectService.selectAll();
    }
}
